<%@page import="entities.Category"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="entities.Author"%>
<%@page import="java.util.Map"%>
<%@page import="entities.Question"%>
<%@page import="java.util.List"%>
<%
List<Question> questions = (List<Question>) request.getAttribute("questions");
Map<String, Author> authors = (Map<String, Author>) request.getAttribute("authors");
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");

//Paginator
int limit = (Integer) request.getAttribute("limit");
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp" />
		<div class="mainContent clearafter">
			<div class="leftMainContent">
				<div class="adv top">
					<script type="text/javascript"><!--
					google_ad_client = "ca-pub-2883566427648799";
					/* question 468x60 */
					google_ad_slot = "8574497481";
					google_ad_width = 468;
					google_ad_height = 60;
					//-->
					</script>
					<script type="text/javascript"
					src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
					</script>
				</div>
				
				<!-- TAB -->
				<ul id="tab" class="clearafter">
					<li class="active"><a href="/">Lastest Question</a></li>
					<li><a href="/recently">Recently Question</a></li>
				</ul>
				<!-- END TAB -->
				
				<!-- Content Tab -->
				<div class="content">
					<div class="content_in">
						<!-- question adv -->
						<div class="question_item clearafter">
							<span class="total_answers">
								<a href="javascript: return false">0</a> Answers
							</span>
							<div class="adv">
								<script type="text/javascript"><!--
								google_ad_client = "ca-pub-2883566427648799";
								/* question 468x60 */
								google_ad_slot = "8574497481";
								google_ad_width = 468;
								google_ad_height = 60;
								//-->
								</script>
								<script type="text/javascript"
								src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
								</script>
							</div>
						</div>
						<!-- end question adv -->
						
						<% 
						for (int i = 0; i < questions.size(); i++) {
							if (i >= limit) break;
							Author author = authors.get(questions.get(i).getAuthor());
							Category category = categories.get(questions.get(i).getCategory());
						%>
						
						<!-- question_item -->
						<div class="question_item clearafter">
							<span class="total_answers">
								<a href="/q/<%=questions.get(i).getId()%>"><%=questions.get(i).getAnswers().size() %></a> Answers
							</span>
							<h3>
								<a href="/q/<%=questions.get(i).getId()%>" title="<%=questions.get(i).getTitle()%>"><%=questions.get(i).getTitle() %></a>	
							</h3>
							<p>
								<% if (author != null) { %>
								<span class="user">
									Asked by: 
									<strong>
										<a href="/a/<%=author.getAlias() %>-<%=author.getId() %>" title="<%=author.getName() %>"><%=author.getName() %></a>
									</strong>
								</span>
								<% } %>
								 <% if (category != null) { %>
								<span class="pcate">
									<a rel="tag" href="/c/<%=category.getAlias() %>-<%=category.getId()%>"><%=category.getName() %></a><br>
								</span>
								<% } %>
							</p>
							<% if (i < 2) { %>
							<div class="adv">
								<script type="text/javascript"><!--
								google_ad_client = "ca-pub-2883566427648799";
								/* link_menu 468x15 */
								google_ad_slot = "8735411486";
								google_ad_width = 468;
								google_ad_height = 15;
								//-->
								</script>
								<script type="text/javascript"
								src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
								</script>
							</div>
							<% } %>
						</div>
						<!-- end question_item -->
						<% } %>
						
						<!-- pagination -->
						<div class="pagination">
							<%
							List<Integer> range = paginator.getRangePage();
							%>
							<% if (prevPage) { %>
							<a href="<%=paginator.getPrev()%>">
								<strong>«</strong>
							</a>
							<% } %>
							
							<%
							if (nextPage || prevPage) {
								for (int i = 0; i < range.size(); i++) {
									if (range.get(i).intValue() == pages) {
							%>
								<strong class="on"><%=range.get(i).toString() %></strong>
								<%  } else if (nextPage || (!nextPage && range.get(i).intValue() <= pages)) { %>
								<a href="<%=paginator.getPage(range.get(i).intValue()) %>"><%=range.get(i).toString() %></a>
								<%  } %>
							<%  }
							} %>
							<% if (nextPage) { %>
							<a href="<%=paginator.getNext()%>">»</a>
							<% } %>
						</div>
						<!-- end pagination -->
					</div>
				</div>
				<!-- End Content tab -->
			</div>
			<jsp:include page="/elements/right.jsp" />
		</div>
<jsp:include page="/layouts/footer.jsp" />